﻿using System;
using System.IO;
using NUnit.Framework;

namespace Dgg.LearnYourTools.NUnit.C_Assertions
{
	[TestFixture]
	public class _017_AMatterOfStyleOr
	{
		[Test]
		public void ClassicAssertions()
		{
			Assert.True(true);
			string s = null;
			Assert.Null(s);
			int expected = 5, actual = 10;
			Assert.AreNotEqual(expected, actual);
			Assert.AreSame("da", "da");
			Assert.GreaterOrEqual(3f, 3f);
			Stream ms = new MemoryStream();
			Assert.IsAssignableFrom(typeof(MemoryStream), ms);
			Assert.IsInstanceOf(typeof(Stream), ms);
			CollectionAssert.IsOrdered(new[] { 3, 5, 7 });
		}

		[Test]
		public void ConstraintAssertions()
		{
			Assert.That(true, Is.True);
			string s = null;
			Assert.That(s, Is.Null);
			int expected = 5, actual = 10;
			Assert.That(actual, Is.Not.EqualTo(expected));
			Assert.That("da", Is.SameAs("da"));
			Assert.That(3f, Is.GreaterThanOrEqualTo(3f));
			Stream ms = new MemoryStream();
			Assert.That(ms, Is.AssignableFrom(typeof(MemoryStream)));
			Assert.That(ms, Is.InstanceOf<Stream>());

			Assert.That(new[] { 3, 5, 7 }, Is.Ordered);
		}

		[Test]
		public void Extra_Constraints()
		{
			Assert.That(5, Is.InRange(0, 6));
			Assert.That(new int[0], Is.Empty);
			Assert.That("", Is.Empty);
			Assert.That(3d, Is.Not.NaN);
			Assert.That("The End", Is.StringEnding("nd"));
			Assert.That(new MemoryStream(), Has.Property("Capacity").EqualTo(0));

			Assert.That(typeof(Decorated), Has.Attribute<SerializableAttribute>());
			Assert.That(new Decorated(), Is.BinarySerializable);
		}

		[Serializable]
		class Decorated { }
	}
}
